package com.learn.xueer.ui.widgets;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Path;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.widget.FrameLayout;

public class GlobalMaskView extends FrameLayout {

    private Paint paint;
    private Path path;

    public GlobalMaskView(Context context) {
        super(context);
        init();
    }

    public GlobalMaskView(Context context, AttributeSet attrs) {
        super(context, attrs);
        init();
    }

    private void init() {
        paint = new Paint(Paint.ANTI_ALIAS_FLAG);
        paint.setColor(Color.parseColor("#66000000")); // 半透明遮罩颜色
        path = new Path();
    }

    @Override
    protected void onSizeChanged(int w, int h, int oldw, int oldh) {
        super.onSizeChanged(w, h, oldw, oldh);
        path.reset();
        path.addRect(0, 0, getWidth(), getHeight(), Path.Direction.CW);
    }

    @Override
    public boolean onInterceptTouchEvent(MotionEvent ev) {
        return false; // 不拦截所有触摸事件
    }

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        canvas.drawPath(path, paint);
    }
}